package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.mz.ozy.R;
import com.mz.ozy.bean.ShopSpecListBean;
import com.mz.ozy.widget.flowlayout.FlowLayout;
import com.mz.ozy.widget.flowlayout.TagFlowAdapter;
import com.mz.ozy.widget.flowlayout.TagFlowLayout;

import java.util.List;

public class SpecTagAdapter extends TagFlowAdapter<ShopSpecListBean.ShopSpecBean> {
    private final Context mContext;
    private final LayoutInflater inflater;
    private TagFlowLayout mRootView;
    private int mSelectPosition = 0;

    public SpecTagAdapter(Context context, TagFlowLayout roorView, List<ShopSpecListBean.ShopSpecBean> datas, int position) {
        super(datas);
        mRootView = roorView;
        mContext = context;
        mSelectPosition = position;
        inflater = LayoutInflater.from(mContext);
    }

    public void setSelectPosition(int selectPosition) {
        mSelectPosition = selectPosition;
        notifyDataChanged();
    }

    @Override
    public View getView(FlowLayout parent, int position, ShopSpecListBean.ShopSpecBean s) {
        TextView tv = (TextView) inflater.inflate(R.layout.item_shop_detail_tag, mRootView, false);
        tv.setText(s.getName());
        if (mSelectPosition == position) {
            tv.setBackgroundResource(R.drawable.bg_solid_73b21a_14dp);
            tv.setTextColor(ContextCompat.getColor(mContext, R.color.white));
        } else {
            tv.setBackgroundResource(R.drawable.bg_solid_f5f5f5_14dp);
            tv.setTextColor(ContextCompat.getColor(mContext, R.color.c_1d1d1d));
        }
        return tv;
    }
}
